package top.kaoshanji.p1ch03a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单-p1ch03a-55页a：定义第一个类
 * author kaoshanji
 * ^_^
 * create time 2025/2/16 18:35
 */
public class Point {

    private static final Logger logger = LogManager.getLogger(Point.class);

    public static void main(String[] args) {

        logger.info("...代码清单-p1ch03a-55页a：定义第一个类...");

        Point p1 = new Point();
        p1.setX(2);
        p1.setY(3);

        System.out.println(p1.getX() + "," + p1.getY() + "," + p1.distance());

        Point p2 = new Point(4, 5);
        System.out.println(p2.getX() + "," + p2.getY() + "," + p2.distance());

    }

    private int x;
    private int y;

    public Point() {
        this(0, 0);
    }

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public double distance() {
        return Math.sqrt(x*x + y*y);
    }

    public double distance(Point p) {
        return Math.sqrt(Math.pow(x-p.getX(), 2) + Math.pow(y-p.getY(), 2));
    }

}
